import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginGuard } from 'src/app/common/guards/login.guard';
import { PageComponent } from './layout/page/page.component';

const routes: Routes = [
  {
    path: '',
    redirectTo: 'home',
    pathMatch: 'full',
  },
  {
    path: 'home',
    canActivate: [LoginGuard],
    component: PageComponent,
    data: {
      title: '首页',
    },
    children: [
      {
        path: '',
        redirectTo: 'index',
        pathMatch: 'full',
      },
      {
        path: 'index',
        loadChildren: () =>
          import('./pages/home/home.module').then((m) => m.HomeModule),
        data: {
          title: '首页',
        },
      },
      {
        path: 'template',
        loadChildren: () =>
          import('./pages/template/template.module').then(
            (m) => m.TemplateModule
          ),
        data: {
          title: '代码示例',
        },
      },
      {
        path: 'test',
        loadChildren: () =>
          import('./pages/test/test.module').then((m) => m.TestModule),
        data: {
          title: '代码测试',
        },
      },
    ],
  },
  {
    path: 'auth',
    loadChildren: () =>
      import('./pages/auth/auth.module').then((m) => m.AuthModule),
  },
  {
    path: '**',
    redirectTo: '/auth/not-found',
    pathMatch: 'full',
  },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
})
export class AppRoutingModule {}
